//
//  DMLoginVC.m
//  DistributionMall
//
//  Created by JHnoplan on 2018/10/14.
//  Copyright © 2018年 JHnoplan. All rights reserved.
//

#import "DMLoginVC.h"
#import "DMRegisterVC.h"
#import "DMForgetVC.h"
#import "DMTabBarController.h"

//request
#import "DMLoginAndRegisterRequest.h"
//other
#import "AppDelegate.h"

@interface DMLoginVC ()

@property (weak, nonatomic) IBOutlet UITextField *phoneTF;
@property (weak, nonatomic) IBOutlet UITextField *passwordTF;
@property (weak, nonatomic) IBOutlet UIView *firstLine;
@property (weak, nonatomic) IBOutlet UIView *secondLine;
@property (weak, nonatomic) IBOutlet UILabel *firstWrongLb;
@property (weak, nonatomic) IBOutlet UILabel *secondWrongLb;





@end

@implementation DMLoginVC

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
}
-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    self.phoneTF.text = @"13104851701";
//    self.passwordTF.text = @"123456";
}

//登录
- (IBAction)loginClick:(UIButton *)sender {
    NSString * PWDstr = [self.passwordTF.text md5String];
    
    DMLoginAndRegisterRequest * request = [[DMLoginAndRegisterRequest alloc]initWithloginPhone:self.phoneTF.text PWD:PWDstr];
    
    [JLProgressHUDManager showLoadingHud];
    MJWeakSelf
    [request newStartRequestWithCompletion:^(KBaseModel *baseModel) {
        [JLProgressHUDManager hideHud];
        KUserBaseModel * userBaseModel = [KUserBaseModel modelWithJSON:baseModel.data];
        [KuserInfo shareInstance].userModel = userBaseModel.partyView;
        [KuserInfo shareInstance].userModel.sid = userBaseModel.sid;
        [KuserInfo shareInstance].userModel.phone = weakSelf.phoneTF.text;
        [KuserInfo shareInstance].userModel.password = PWDstr;
        [KuserInfo shareInstance].isLogin = YES;
        [[KuserInfo shareInstance] archiveUserInfo];
        AppDelegate* app = (AppDelegate*)[UIApplication sharedApplication].delegate;
        app.window.rootViewController = [DMTabBarController new];
        
    } failure:^(KBaseModel *errorModel) {
        
        [JLProgressHUDManager showErrorHud:errorModel.msg];
    }];

}
//新用户注册
- (IBAction)registerClick:(UIButton *)sender {
    DMRegisterVC *vc = [DMRegisterVC new];
    [self.navigationController pushViewController:vc animated:YES];
}
//忘记密码
- (IBAction)forgetClick:(UIButton *)sender {
    DMForgetVC *vc = [DMForgetVC new];
    [self.navigationController pushViewController:vc animated:YES];
}


@end
